package org.hhchat.others.q360;

import java.util.Scanner;

/**
 * Created this one by HMH on 2017/8/26.
 */

public class exam01 {
    static int m,n,a,b,c,d,x,y,z;
    static int best=Integer.MIN_VALUE;

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        a = scanner.nextInt();
        b = scanner.nextInt();
        c = scanner.nextInt();
        d = scanner.nextInt();
        x = scanner.nextInt();
        y = scanner.nextInt();
        z = scanner.nextInt();
        for(int i = 0; i<100; i++) {
            for(int j=0;j<100;j++) {
                for(int k=0;k<100;k++) {
                    isOk(i, j, k);
                }
            }
        }
        System.out.println(best);
    }

    public static void isOk(int i,int j,int k){
        boolean ans1 = (a*i+d*k)<=n;
        boolean ans2 = (b*i+c*j)<=m;
        if(ans1&&ans2&&best<i*x+j*y+k*z){
            best = i * x + j * y + k * z;
        }
    }

}
